package com.xuwang.controller;

import com.xuwang.pojo.Additive;
import com.xuwang.pojo.Production;
import com.xuwang.service.impl.ProductionServiceImpl;
import com.xuwang.vo.ProductionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 生产表(Production)表控制层
 *
 * @author abaaba
 * @since 2021-09-17 09:43:38
 * @version 1.0
 */
@RestController
@RequestMapping("/production")
@Api(value = "生产表(Production)管理",tags = "生产表(Production)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class ProductionController {
    /**
     * 服务对象
     */
    @Resource
    private ProductionServiceImpl productionServiceImpl;

    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPageZF", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "index",value = "第几页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "page",value = "没也多少",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "productionType",value = "生产类型（123）",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "matchName",value = "对应生产物名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "Company",value = "公司名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "batchNo",value = "生产批号",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "beginTime",value = "开始时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "endTime",value = "结束时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "warranty",value = "保质期",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "isDelete",value = "是否删除01",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> selectForPageZF(
            @RequestParam(name = "index") int index,@RequestParam(name = "page") int page,
            Integer productionType,String matchName,String Company,String batchNo,String beginTime,String endTime,Integer warranty,String isDelete) {
        return this.productionServiceImpl.selectForPageZF(index, page,productionType,matchName,Company,batchNo,beginTime,endTime,warranty,isDelete);
    }
    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPageQY", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "index",value = "第几页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "page",value = "没也多少",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "productionType",value = "生产类型（123）",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "matchName",value = "对应生产物名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "batchNo",value = "生产批号",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "beginTime",value = "开始时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "endTime",value = "结束时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "warranty",value = "保质期",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "isDelete",value = "是否删除01",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> selectForPageQY(
            @RequestParam(name = "index") int index,@RequestParam(name = "page") int page,
            Integer productionType,String matchName,String batchNo,String beginTime,String endTime,Integer warranty,String isDelete,
            @Autowired HttpServletRequest request) {
        return this.productionServiceImpl.selectForPageQY(index, page,productionType,matchName,batchNo,beginTime,endTime,warranty,isDelete,request);
    }

    /**
     * 查询添加剂的使用情况（政府查看）
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAddUse", method = RequestMethod.GET)
    @ApiOperation(value = "查询添加剂的使用情况（政府查看）",notes = "查询添加剂的使用情况（政府查看）",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "index",value = "第几页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "page",value = "每页多少",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "batchNo",value = "菜品生产批号",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "foodName",value = "菜品名",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "beginTime",value = "开始时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "endTime",value = "结束时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "additiveName",value = "添加剂名",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "number",value = "数量",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "companyName",value = "使用公司的名字",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> selectAddUse( @RequestParam(name = "index") int index,@RequestParam(name = "page") int page,
                                             String batchNo,String foodName,String beginTime,String endTime,String additiveName,Double number,String companyName) {
        return this.productionServiceImpl.selectAddUse(index,page,batchNo,foodName,beginTime,endTime,additiveName,number,companyName);
    }



//    /**
//     * 查询所有数据
//     * @return 返回所有数据
//     */
//    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
//    @ApiOperation(value = "查询所有数据接口",notes = "查询所有数据接口",httpMethod = "GET")
//    public Map<String, Object> selectAll() {
//        return this.productionServiceImpl.selectAll();
//    }


    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
//     * @param isDelete 是否已删除
     * @return 单条数据
     */
    @RequestMapping(value = "/updateIsDeleteById", method = RequestMethod.POST)
    @ApiOperation(value = "根据一个主键修改一条删除状态的接口",notes = "根据一个主键修改一条删除状态的接口",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
//            @ApiImplicitParam(name = "isDelete",value = "是否删除",paramType = "query",dataType = "int",required = true),
    })
    public Map<String, Object> updateIsDeleteById(@RequestParam("id") String id) {
        return this.productionServiceImpl.updateIsDeleteById(id);
    }

    /**
     * 批量删除多条数据
     *
     * @param ids 批量主键
     * @return 单条数据
     */
    @RequestMapping(value = "/updateIsDeleteByIds", method = RequestMethod.POST)
    @ApiOperation(value = "删除多条的接口",notes = "删除多条的接口",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "主键",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> updateIsDeleteByIds(@RequestParam("ids") String ids) {
        return this.productionServiceImpl.updateIsDeleteByIds(ids);
    }

    /**
     * 直接从别人库存进货的时候，查看其他企业的库存，根据名字返回批号，货物名、库存量、对应库存企业。
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectBatchByMyCompany", method = RequestMethod.GET)
    @ApiOperation(value = "查询本公司存有物品批号",
            notes = "查询本公司存有物品批号",httpMethod = "GET")
    public Map<String, Object> selectBatchByMyCompany(@Autowired HttpServletRequest request) {
        return this.productionServiceImpl.selectBatchByMyCompany(request);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    @ApiOperation(value = "通过主键查询一个**的接口",notes = "通过主键查询一个**的接口",httpMethod = "GET")
    public Map<String, Object> selectById(Integer id) {
        return this.productionServiceImpl.selectById(id);
    }

    /**
     * 通过主键更新单条数据(传入所有信息除了sup)
     *
     * @param production 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @Transactional
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    @ApiOperation(value = "通过主键更新一个**的接口",notes = "通过主键更新一个**的接口",httpMethod = "POST")
    public Map<String, Object> updateById(@RequestBody @ApiParam(name = "production(传递id,productionType,matchId,batchNo,productionNumber,specification,matchName,warranty)",value = "pojo模型,传递id,",required = true) Production production
                                        ,@Autowired HttpServletRequest request  ) {
        return this.productionServiceImpl.updateById(production,request);
    }
    
    /**
     * 新增一条生产记录
     *
     * @param productionVO 生产表VO模型
     * @return 返回插入的主键id
     */
    @Transactional
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "生产的接口",notes = "生产的接口",httpMethod = "POST")
    public Map<String, Object> insert(@RequestBody @ApiParam(name = "productionVO",value = "VO模型",required = true) ProductionVO productionVO, @Autowired HttpServletRequest request) {
        return this.productionServiceImpl.insert(productionVO,request);
    }

    /**
     * 查询本公司可生产的东西
     */
    @RequestMapping(value = "/selectProduction", method = RequestMethod.GET)
    @ApiOperation(value = "查询本公司能生产的东西",notes = "查询本公司能生产的东西",httpMethod = "GET")
    public Map<String, Object> selectProduction(@Autowired HttpServletRequest request) {
        return this.productionServiceImpl.selectProduction(request);
    }

}